SERIAL ADC PIC TRICK

Dear EPE,

Readers might be interested in my PIC program for use with the TLC548/9
8-bit serial analogue-to-digital converter. I use file registers COUNT and
TEMP as sort of "standard" registers, COUNT for timing etc and TEMP as a
sort of second W. It helps me get a mental view of my progs.

In the program this routine comes from, COUNT has previously been reset
through DECFSZ, so I can get away with BSF COUNT,3. I have run this at 6MHz
without problem, and it should go faster. The A-D value is stored in file
UNIT.

A2DIN: BCF PORTB,7    ; clear CS line to hold value to send
       BSF COUNT,3    ; set count to shift 8 bits (make sure
                      ; COUNT cleared before this section or use MOVLW etc)
FETCH: RLF UNIT,F     ; move bits one place left & store new value in UNIT
       BCF UNIT,0     ; set 0 value before Portb,0 bit test
       BSF PORTB,6    ; set A2D clock pin high, release bit for transfer
       BTFSS PORTB,5  ; is bit 0 (DOUT)set ?
       GOTO NEXT1     ; no, then leave UNIT bit 0 value as is
       BSF UNIT,0     ; yes, set bit 0 of UNIT
NEXT1: BCF PORTB,6    ; clear clock pin
       DECFSZ COUNT,F ; is COUNT zero?
       GOTO FETCH     ; no, get another bit!
       BSF PORTB,7    ; yes, 8 bits clocked out & held in UNIT,
                      ; set CS line to get new value
       RETURN

Graham Card, via email
